<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no" />
<title>确认订单</title>
<link rel="stylesheet" href="<%=basePath%>assets/css/reset.css">
<link rel="stylesheet" href="<%=basePath%>assets/css/page.css">
<link rel="stylesheet" href="<%=basePath%>assets/font-awesome-4.7.0/css/font-awesome.min.css">
<script src="<%=basePath%>assets/js/jquery-2.1.1.min.js"></script>
<script src="<%=basePath%>assets/js/page.js"></script>
<link rel="stylesheet" href="<%=basePath%>assets/css/public.css">
<script src="<%=basePath%>assets/js/fontSize.js"></script>
<link href="<%=basePath%>/assets/layer/mobile/need/layer.css" rel="stylesheet" type="text/css">
<script src="<%=basePath%>/assets/layer/mobile/layer.js"></script>
<link rel="stylesheet" href="<%=basePath%>/assets/imgTools/helmet.css">
<style type="text/css">
body {
	padding-top: 0.8rem;
	padding-bottom: 44px;
}

.order>li>.order_list1>.content>span {
	line-height: 0.3rem;
}

.order>li>.order_list1>.content>a>p {
	line-height: 0.3rem;
}

.shopping_bar2 {
	bottom: 0
}

.shouhuodizhi {
	width: 100%;
}

.dwIcon {
	width: 12%;
}

.dwIcon img {
	width: 36%;
	display: block;
	margin: 0.2rem 20%
}

.shouhuodizhi_xq {
	width: 75%;
}

.shouhuorenxinxi span {
	font-size: 0.28rem;
	height: 0.6rem;
	line-height: 0.6rem;
}

.tiaozhuan {
	width: 13%
}

.xingxidizhi {
	font-size: 0.22rem;
	line-height: 0.3rem;
}

.shouhuodizhi .tiaozhuan a {
	font-size: 0.3rem;
	line-height: 0.8rem;
	height: 0.8rem;
	display: block;
	width: 0.8rem;
	text-align: right;
	margin-right: 0.25rem;
	margin-top: 0.2rem;
	background: url(<%=basePath%>/assets/img/arrow2.png) no-repeat right center;
	background-size: 20%
}
</style>
</head>
<body>
	<input id="basePath" type="hidden" value="<%=basePath%>">
	<div class="header">
		<div class='header_top'>
			<a class="returnInfo" href="#" onclick="javascript:history.go(-1);"><i class="fa fa-angle-left"></i></a>
			确认订单
		</div>
	</div>

	<c:if test="${personDefaultAddress ne null}">
		<div class="shouhuodizhi clearFirx border-bottom-8" onclick="toSelectAddress()">
			<div class="dwIcon float_l">
				<img src="<%=basePath%>assets/images/dingwei.png" alt="">
			</div>
			<div class="shouhuodizhi_xq float_l">
				<p class="shouhuorenxinxi clearFirx">
					<span class="shrxingming float_l">收货人：${personDefaultAddress.userName}</span>
					<span class="shrdianhua float_r">${personDefaultAddress.userPhone}</span>
				</p>
				<p class="xingxidizhi">收货地址：${personDefaultAddress.province}${personDefaultAddress.city}${personDefaultAddress.county}${personDefaultAddress.address}</p>
			</div>
			<div class="tiaozhuan float_l">
				<a href="javascript:;" class="float_r"></a>
			</div>
		</div>
	</c:if>
	<c:if test="${personDefaultAddress eq null}">
		<div class="shouhuodizhi clearFirx border-bottom-8" onclick="toAddAddress()">
			<div class="dwIcon float_l">
			</div>
			<div class="shouhuodizhi_xq float_l" style="text-align: center;width: 100%;">
				<p class="shouhuorenxinxi clearFirx" >
					<span class="shrdianhua" style="line-height: 1.0rem;font-size: 0.32rem;">+</span>&emsp;<span class="shrdianhua" style="line-height: 1.0rem;font-size: 0.32rem;">新建收货地址</span>
				</p>
			</div>
		</div>
	</c:if>


	<ul class="order" id="goods">
		<c:forEach items="${orderList}" var="orderList">
			<li>
				<h2>
					<div class="content">
						<a style='font-size: 1.08em; display: block; width: 100%;'
							href="<%=basePath%>app/goodsList?merchantId=${orderList.merchantId}"
							class="clearFirx"> <i style='float: left; display: block'>${orderList.merchantName}
						</i> <img src='<%=basePath%>assets/img/arrow2.png'
							style='float: left; display: block; height: 11px; margin: 10px 0 0 8px;'>
						</a>
					</div>
				</h2> 
				<c:forEach items="${orderList.shoppingGoodsList}"
					var="shoppingGoodsList">
					<div class="order_list1" style="background: #fafafa;">
						<div class="content">
							<a href="#"> 
								<img src="<%=basePath%>/app/getGoodsPhotoByName?goodsImage=${shoppingGoodsList.goodsThums}" alt="">
								<p class="goodsName">${shoppingGoodsList.goodsName}</p>
							</a>
							<span>￥${shoppingGoodsList.unitPrice} <em>x${shoppingGoodsList.orderCount}</em></span>
						</div>
					</div>
				</c:forEach>
			</li>
		</c:forEach>
	</ul>

	<div class="shopping_bar2" style="font-size: 16px">
		<p style="padding-left: 10px;">
			共 <em style="color: red">${orderCount}</em> 件， 总金额 
			<span id="total_price"></span> <em style="color: red">￥${orderPricre}</em>
		</p>
		<a href="#" id="btn">提交订单</a>
	</div>
</body>
<script type="text/javascript">
	$(function(){
		$('.order').find('li .order_list1').each(function(){
			var goodsNameHtml = $(this).find('.goodsName').html();
			$(this).find('.goodsName').html(showText(goodsNameHtml, 31))		
		})
		
		$("#btn").click(function(){
			var obj = "${empty personDefaultAddress}";
			if(obj == "true"){
				layer.open({
  			    	content: '请选择收货地址'
      			    ,skin: 'msg'
      			    ,time: 2 //2秒后自动关闭
  			  	});
			}else{
				var a = '${personDefaultAddress.userName}';
				var b = '${personDefaultAddress.userPhone}';
				var c = '${personDefaultAddress.province}'+'${personDefaultAddress.city}'+'${personDefaultAddress.county}'+'${personDefaultAddress.address}';
				$.ajax({
					url: $("#basePath").val()+"app/shoppingCardOrder",
				    timeout: 300000,
				    dataType: "json",
				    type: "post",
				    data: {
				    	"userName":a,
				    	"userPhone":b,
				    	"userAddress":c,
				    },success: function (data) {
				    	window.location.href = $("#basePath").val()+"app/getUserOrderList";
			        },error: function (data) {
	        	 		layer.open({
	      			    	content: '网络有点延迟，客官请稍等～'
		      			    ,skin: 'msg'
		      			    ,time: 2 //2秒后自动关闭
	      			  	});
			        }
				})
			}
		});
	})

	//选择订单地址
	function toSelectAddress(){
		window.location.href="<%=basePath%>app/toSelectAddress?state=1";
	};
	function showText(text, numSub) {
		if (text == null) {
			return "";
		}
		if (text.length > numSub) {
			return text.substring(0, numSub) + "...";
		}
		return text;
	}
	//跳新增地址
	function toAddAddress(){
		window.location.href="<%=basePath%>jsp/app/addAddress.jsp";
	}
</script>
</html>